package puziran.sofa.util;

import java.util.List;

public class PageModelCommon
{
  private int totalRecords;
  private List<Object> resultList;
  private int pageNo;
  private int pageSize;

  public int getTotalPages()
  {
    if (this.totalRecords == 0)
      return 1;
    return (this.totalRecords + this.pageSize - 1) / this.pageSize;
  }

  public int getTotalRecords() {
    return this.totalRecords;
  }
  public void setTotalRecords(int totalRecords) {
    this.totalRecords = totalRecords;
  }
  public List<Object> getResultList() {
    return this.resultList;
  }
  public void setResultList(List<Object> filesFromDB) {
    this.resultList = filesFromDB;
  }
  public int getPageNo() {
    return getTotalPages() == 0 ? 1 : this.pageNo;
  }
  public void setPageNo(int pageNo) {
    this.pageNo = pageNo;
  }
  public int getPageSize() {
    return this.pageSize;
  }
  public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
  }
  public int getTopPageNo() {
    return 1;
  }
  public int getPreviousPageNo() {
    if (this.pageNo == 1) {
      return 1;
    }
    return this.pageNo - 1;
  }

  public int getNextPageNo() {
    if (this.pageNo == getBottomPageNo()) {
      return getBottomPageNo();
    }
    return this.pageNo + 1;
  }

  public int getBottomPageNo() {
    return getTotalPages();
  }
}